package com.iss.lxhproject.controller;


import com.iss.lxhproject.entity.Consume;
import com.iss.lxhproject.model.MyResponseData;
import com.iss.lxhproject.service.ConsumeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("consumer/")
public class ConsumerController {
    private int  count=-1;
    @Autowired
    ConsumeService service;
    @RequestMapping("insertConsume")
    public MyResponseData insertConsume(Consume consume){
        MyResponseData responseData = new MyResponseData();
        count=service.insertConsume(consume);
        if (count > 0) {
            responseData.setErrorCode(0);
            responseData.setStatus("成功");
        } else {
            responseData.setErrorCode(-1);
            responseData.setStatus("失败");
        }
        return responseData;
    }
    @RequestMapping("selectAllConsume")
    public List<Consume> selectAllConsume(){
        return service.selectAllConsume();
    }


    @RequestMapping("deleteConsume")
    public MyResponseData deleteConsume(Integer[] consume_id){
        MyResponseData responseData = new MyResponseData();
        count=service.deleteConsume(consume_id);
        if (count > 0) {
            responseData.setErrorCode(0);
            responseData.setStatus("成功");
        } else {
            responseData.setErrorCode(-1);
            responseData.setStatus("失败");
        }
        return responseData;

    }
    @RequestMapping("updateConsume")
    public MyResponseData updateConsume(Consume consume){
        MyResponseData responseData = new MyResponseData();
        count=service.updateConsume(consume);
        if (count > 0) {
            responseData.setErrorCode(0);
            responseData.setStatus("成功");
        } else {
            responseData.setErrorCode(-1);
            responseData.setStatus("失败");
        }
        return responseData;

    }

    @RequestMapping("selectConsumeById")
    public MyResponseData selectConsumeById(Integer consume_id){
        MyResponseData responseData = new MyResponseData();
        Consume consume=service.selectConsumeById(consume_id);
        if (consume!=null) {
            responseData.setErrorCode(0);
            responseData.setStatus("成功");
            responseData.setObject(consume);
        } else {
            responseData.setErrorCode(-1);
            responseData.setStatus("失败");
        }
        return responseData;
    }








}
